using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Collections.Specialized;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Xml;
using System.IO;
using System.Runtime.Serialization;
using System.Xml.Serialization;

namespace TST.SharePoint.Shared
{
    [Serializable()]
    public class Filter : IIdentifiable<string>
    {
        private string _id;
        private Field _field;
        private FilterOperator _operator;
        private FilterValues _filterValues;
        private FilterOperand _operand;

        protected Filter()
        {
            _filterValues = new FilterValues();
            _operand = FilterOperand.And;
        }

        public Filter(Field field)
        {
            _filterValues = new FilterValues();
            if (field != null)
            {
                _id = field.Id;
                _field = field;
            }
        }

        public Field Field
        {
            get { return _field; }
            set { _field = value; }
        }

        public FilterOperator FilterOperator
        {
            get { return _operator; }
            set { _operator = value; }
        }

        public FilterOperand FilterOperand
        {
            get { return _operand; }
            set { _operand = value; }
        }

        [XmlArray("FilterValues"), XmlArrayItem("FilterValue", typeof(FilterValue))]
        public FilterValues FilterValues
        {
            get { return _filterValues; }
            set { _filterValues = value; }
        }

        #region IIdentifiable<string> Members

        public string Id
        {
            get { return _id; }
            set { _id = value; }
        }

        #endregion
    }

    public enum FilterOperator
    {
        Equals,
        Contains,
        BeginsWith,
        EndsWith,
        NotEqual,
        Like,
        Bigger,
        BiggerOrEqual,
        Smaller,
        SmallerOrEqual,
        None
    }

    public enum FilterOperand
    {
        And,
        Or
    }

}
